#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

typedef long long LL;

const int N = 1e5 + 10, M = 1e6 + 10;

bool st[N];
struct node{
	int x, y, z, h;
}a[M];
int hi[N];

int fa[N];

int cnt, ret;
int n, m;

vector<int> edges[N];

void dfs(int u)
{
	st[u] = true;
	cnt++;
	for(auto v : edges[u])
	{
		if(!st[v]) dfs(v);
	}
}

int find(int x)
{
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

bool cmp(node& x, node& y)
{
	if(x.h != y.h) return x.h < y.h;
	else return x.z < y.z;
}

void kruskal()
{
	for(int i = 1; i <= n; i++) fa[i] = i;
	sort(a + 1, a + 1 + m, cmp);
	for(int i = 1; i <= m; i++)
	{
		int x = a[i].x, y = a[i].y, z = a[i].z;
		int fx = find(x), fy = find(y);
		if(fx != fy && st[x] && st[y])
		{
			ret += z;
			fa[fx] = fy;
		}
	}
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) 
	{
		cin >> hi[i];
	}
	for(int i = 1; i <= m; i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].z;
		a[i].h = max(hi[a[i].x], hi[a[i].y]);
		if(hi[a[i].x] >= hi[a[i].y]) edges[a[i].x].push_back(a[i].y);
		if(hi[a[i].y] >= hi[a[i].x]) edges[a[i].y].push_back(a[i].x);
	}
	
	dfs(1);
	cout << cnt << " ";
	kruskal();
	cout << ret << endl;
	return 0;
}
